var id = getUrlParam('id');
layui.use(['element','layer','table','dtree'],  function () {
    form = layui.form;
    layer = layui.layer;
    axios.get(ctx + 'sys/info/info/' + id).then(function (res) {
        console.log(res);
        $('.wrapper').html(
            '<div class="layui-form-item">'
            +  '<label class="layui-form-label">id</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="id" autocomplete="off" placeholder="Id" class="layui-input" value="' + res.data.info.id + '">'
            +  '</div>'
            +  '</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">负责人ID</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="userId" autocomplete="off" placeholder="负责人ID" class="layui-input" value="' + res.data.info.userId + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">责任领导</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="dutyUserName" autocomplete="off" placeholder="责任领导" class="layui-input" value="' + res.data.info.dutyUserName + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">企业名称</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="orgName" autocomplete="off" placeholder="企业名称" class="layui-input" value="' + res.data.info.orgName + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">企业地址</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="orgAdd" autocomplete="off" placeholder="企业地址" class="layui-input" value="' + res.data.info.orgAdd + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">主要业务活动</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="business" autocomplete="off" placeholder="主要业务活动" class="layui-input" value="' + res.data.info.business + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">专业</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="special" autocomplete="off" placeholder="专业" class="layui-input" value="' + res.data.info.special + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">法人姓名</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="legal" autocomplete="off" placeholder="法人姓名" class="layui-input" value="' + res.data.info.legal + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">经营状态</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="status" autocomplete="off" placeholder="经营状态" class="layui-input" value="' + res.data.info.status + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">注册资本</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="regCapital" autocomplete="off" placeholder="注册资本" class="layui-input" value="' + res.data.info.regCapital + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">企业联系人</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="contact" autocomplete="off" placeholder="企业联系人" class="layui-input" value="' + res.data.info.contact + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联系人职务</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="contactJob" autocomplete="off" placeholder="联系人职务" class="layui-input" value="' + res.data.info.contactJob + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联系电话</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="contactPhone" autocomplete="off" placeholder="联系电话" class="layui-input" value="' + res.data.info.contactPhone + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">分包单位</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="dept" autocomplete="off" placeholder="分包单位" class="layui-input" value="' + res.data.info.dept + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联系人职务</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="contactJob" autocomplete="off" placeholder="联系人职务" class="layui-input" value="' + res.data.info.contactJob + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">市级分包领导</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="leader" autocomplete="off" placeholder="市级分包领导" class="layui-input" value="' + res.data.info.leader + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">分包领导职务</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="leaderJob" autocomplete="off" placeholder="分包领导职务" class="layui-input" value="' + res.data.info.leaderJob + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联系电话</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="leaderPhone" autocomplete="off" placeholder="联系电话" class="layui-input" value="' + res.data.info.leaderPhone + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联络人</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="leaderContact" autocomplete="off" placeholder="联络人" class="layui-input" value="' + res.data.info.leaderContact + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联络人职务</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="leaderContactJob" autocomplete="off" placeholder="联络人职务" class="layui-input" value="' + res.data.info.leaderContactJob + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">联络人联系电话</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="leaderContactPhone" autocomplete="off" placeholder="联络人联系电话" class="layui-input" value="' + res.data.info.leaderContactPhone + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">创建时间</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="createTime" autocomplete="off" placeholder="创建时间" class="layui-input" value="' + res.data.info.createTime + '">'
            +  '</div>'
            +'</div>'

        );
        form.render();
    })

    form.on('submit(add)', function (data) {
        console.log(data.field);
        data.field['id'] = id;
        axios.post(ctx + 'sys/info/update', data.field).then(function (res) {
            if(res.data.code == 0) {
                layer.msg('保存成功');
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.table.reload();
            }else {
                layer.msg('保存失败');
            }
        }).catch(function (err) {
            console.log(err);
        });
        return false;
    });
});

$('#cancel').click(function () {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
});